<template>
  <div>
    <div
      style="font-size: 16px;font-weight: 500;color: #1D2129;margin-bottom: 16px;"
    >
      定点足球学校已输送情况（累计） <span>单位/人</span>
    </div>

    <div style="display: flex; ">
      <div style="width:50%">
        <div style="font-size: 26px;color: #0F0F0F;">{{ total }}</div>
        <div style="font-size: 12px;">累计输送总人数</div>
      </div>
    </div>

    <div ref="Chart" style="width:100%;height:400px;margin-top:-20px;"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import { get_sheet8_transport } from "@/api/statistics";

export default {
  name: "SchoolType",
  data() {
    return {
      chartData: [],
      total: 0
    };
  },
  mounted() {
    this.datalist();
  },

  methods: {
    async datalist() {
      const res = await get_sheet8_transport({
        year: new Date().getFullYear()
      });
      console.log(res);
      if (res && res.data) {
        this.chartData = res.data.numList;
        this.total = res.data.total;
      }
      // 基于准备好的dom，初始化echarts实例
      this.Chart = echarts.init(this.$refs.Chart);

      // 指定图表的配置项和数据

      const option = {
        barWidth: 20,
        color: ["#EEB74A"],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            crossStyle: {
              color: "#41B776"
            }
          }
        },

        xAxis: [
          {
            rotate: -25, // 旋转角度
            type: "category",
            data: ["国家队", "省队", "市队", "高校高水平运动队", "其他"],
            axisPointer: {
              type: "shadow"
            },
            // 书写格式
            axisLabel: {
              formatter: val => {
                let txt = val;
                if (val.length > 3) {
                  txt = val.substr(0, 3) + "...";
                }
                return txt;
              }
            }
          }
        ],
        yAxis: [
          {
            type: "value",

            min: 0,
            max: 1000,
            interval: 200,
            axisLabel: {
              formatter: "{value} "
            }
          }
        ],
        series: [
          {
            name: "Evaporation",
            type: "bar",
            tooltip: {
              valueFormatter: function(value) {
                return value;
              }
            },
            data: this.chartData
          }
        ]
      };
      // 使用刚指定的配置项和数据显示图表。
      this.Chart.setOption(option);

      // 监听父元素大小变化 刷新图表
      var ro = new ResizeObserver(entries => {
        for (let entry of entries) {
          const cr = entry.contentRect;
          this.Chart.resize();
        }
      });
      // ro.observe(this.$refs.Chart1);
      ro.observe(this.$refs.Chart);
    }
  }
};
</script>

<style scoped>
.dianidan {
  width: 7px;
  height: 7px;
  margin-right: 5px;
  margin-top: 3px;
}
</style>
